<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<p>闭包:函数体内部的变量都可以保存在函数作用域内</p>
<script>
    var scope = "global scope";
    function checkScope(){
        var scope = "local scope";
        function f(){
            return scope;
        }
        return f;
    }
    console.log(checkScope()());

    for(let i=0;i<5;i++){
        console.log(i);
        (()=>{
            console.log("closure"+i);
        })(i)
        document.getElementsByTagName("body")[0].onclick=function(){
            console.log(i);
        }
    }
    console.log(document.domain);
</script>
</body>
</html>
